package com.online.jta.dao;

import javax.annotation.Resource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class UserDao {

    @Resource(name = "jdbcTemplateA")
    private JdbcTemplate jdbcTemplateA;

    @Resource(name = "jdbcTemplateB")
    private JdbcTemplate jdbcTemplateB;

    public void save() {
        String sql = "update users set login_count = login_count + 1,last_login_time = now() where id = 10";
        //第一条insert成功，第二条语句报错，第一条成功回滚
        jdbcTemplateA.update(sql);
        jdbcTemplateB.update("UPDATE JTA SET ID = ID + 1");
        System.out.println(1 / 0);
    }

}
